//
//  PlayViewController.m
//  GC_OC
//
//  Created by 曾 on 2022/1/23.
//

#import "PlayViewController.h"
#import "PlayVideoView.h"
#import "PlayVoiceView.h"
#import "PlayModel.h"
@interface PlayViewController ()
@property (nonatomic, strong)PlayModel*     model;
@property (nonatomic, strong)UIImageView* backImageView;
@property (nonatomic, strong)ObjectAFNetWorking* objectAFN;
@property (nonatomic, strong)NSDictionary* dic;
@property (nonatomic, strong)PlayVideoView* videoView;
@property (nonatomic, strong)PlayVoiceView* voiceView;
@end

@implementation PlayViewController
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:YES];
}
-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor=[UIColor whiteColor];
    self.backImageView=[[UIImageView alloc]initWithFrame:CGRectMake(0,0,SCREEN_WIDTH,SCREEN_HEIGHT)];
    self.backImageView.contentMode=UIViewContentModeScaleAspectFill;
    self.backImageView.clipsToBounds = YES;
    
    UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0,self.backImageView.frame.size.width,self.backImageView.frame.size.height)];
    toolbar.barStyle = UIBarStyleBlack;
    toolbar.alpha=1;

    [self.backImageView addSubview:toolbar];
    [self.view addSubview:self.backImageView];

    [self creatHeadView];

    [self refreshPlay];
}

- (void)dealloc {
    [_voiceView removeView];
    NSLog(@"PlayViewController dealloc");
}

- (void) refreshPlay
{
    CurriculumModel *model = [[PlayModel sharedModel] currentModel];
    if (model != nil) {
        self.voiceView.alpha = 1;
        [self.voiceView refreshUI];
        [self.backImageView sd_setImageWithURL:[NSURL URLWithString:model.image]];
    }
}

-(PlayVoiceView*)voiceView
{
    if(!_voiceView)
    {
        _voiceView=[[PlayVoiceView alloc]initWithFrame:CGRectMake(0,topHeight,SCREEN_WIDTH,SCREEN_HEIGHT-topHeight) andDic:self.dic];
        [self.view addSubview:_voiceView];
    }
    return _voiceView;
}
-(PlayVideoView*)videoView
{
    if(!_videoView)
    {
        _videoView=[[PlayVideoView alloc]initWithFrame:CGRectMake(0,topHeight,SCREEN_WIDTH,SCREEN_HEIGHT-topHeight) andDic:self.dic];
        [self.view addSubview:_videoView];
    }
    return _videoView;
}
-(void)creatHeadView
{
    PlayModel* model=[PlayModel sharedModel];
    UIView* view=[[UIView alloc]initWithFrame:CGRectMake(0,0,SCREEN_WIDTH,topHeight)];
    view.backgroundColor = [[UIColor whiteColor]colorWithAlphaComponent:0.0f];
    CGFloat titleHeight=[GC_OCTool getHeightForLabel:@"A" andFont:[UIFont fontWithName:@"Helvetica-Bold" size:FontSize(17)] andWidth:wid(100)];
    UILabel* titleLabel=[[UILabel alloc]initWithFrame:CGRectMake(wid(65),StatusBarHeight+(topHeight-StatusBarHeight-titleHeight)/2.0,SCREEN_WIDTH-wid(65)*2,titleHeight)];
    titleLabel.textColor=[UIColor whiteColor];
    [titleLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:FontSize(17)]];
    titleLabel.textAlignment=NSTextAlignmentCenter;
    titleLabel.text=model.titleStr;
    [view addSubview:titleLabel];
    
    UIButton* leftbtn=[UIButton new];
    leftbtn.frame=CGRectMake(wid(20),StatusBarHeight+(topHeight-StatusBarHeight-wid(40))/2.0,wid(40),wid(40));
    [leftbtn setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    leftbtn.titleLabel.font=[UIFont systemFontOfSize:12];
    [leftbtn addTarget:self action:@selector(leftBtnAction) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:leftbtn];
    [self.view addSubview:view];
}
-(void)leftBtnAction
{
    [_voiceView removeView];
    [self.navigationController popViewControllerAnimated:YES];
}

@end
